package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Movement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/11 19:26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MovementAdminVo {

    private String id;  // 编号
    private String nickname;
    private Integer userId;
    private String avatar;

    private Integer createDate;
    private String textContent;

    private String[] imageContent;

    private Integer state;
    private Integer commentCount; // 评论数
    private Integer likeCount;
    private Integer loveCount;


    public static MovementAdminVo init(UserInfo userInfo, Movement movement){

        MovementAdminVo vo = new MovementAdminVo();

        BeanUtils.copyProperties(movement, vo);

        if (movement != null){
            vo.setId(movement.getId().toHexString());
            Long created = movement.getCreated();
            vo.setCreateDate(created.intValue());
            vo.setImageContent(movement.getMedias().toArray(new String[0]));
            vo.setUserId(movement.getUserId().intValue());
        }

        BeanUtils.copyProperties(userInfo, vo);

        return vo;
    }
}
